package mediator;

import participant.ParticipantGUI;

import java.util.ArrayList;

/*======================================*/
/* This is the mediator class in the    */
/* mediator design pattern              */
/*======================================*/

public class BusinessMediator {

    private ArrayList<ParticipantGUI> companyList = new ArrayList<>();

    public void register(ParticipantGUI company) {
        companyList.add(company);
    }

    public void addPossibleCus(ParticipantGUI p, String text) {
        for (ParticipantGUI c : companyList) {
            if (c != p) {
                c.addPossibleCustomer(text);
            }
        }
    }

    // update all other User interfaces
    public void updateAllGuis(ParticipantGUI p, String text) {
        for (ParticipantGUI c : companyList) {
            if (c != p) {
                c.displayInfo(text);
            }
        }
    }

    public void writePossibleCusToXmlFile(ParticipantGUI p, String[] cusData) {
        for (ParticipantGUI c : companyList) {
            if (c != p) {
                try {
                    c.writeCandidateCusToXmlFile(cusData);
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            }
        }
    }
}
